package com.timmy.mvpdemo.presenter;

import com.timmy.mvpdemo.interfa.RequestView;
import com.timmy.mvpdemo.interfa.TestCallback;
import com.timmy.mvpdemo.model.RequestMode;

/**
 * Created by Timmy on 2017/12/11.
 */

public class RequestPresenter extends AbstractMvpPersenter<RequestView> {

    private final RequestMode mRequestMode;

    public RequestPresenter() {
        mRequestMode = new RequestMode();
    }

    public void clickRequest() {

        if (getmMvpView() != null) {
            getmMvpView().requestLoading();
        }

        mRequestMode.request(new TestCallback() {
            @Override
            public void onSuccess() {
                getmMvpView().resultSuccess("成功了");
            }

            @Override
            public void onFaild() {
                getmMvpView().resultFailure("失败了");
            }
        });
    }

    /**
     * 取消网络
     */
    public void interruptHttp() {
        mRequestMode.interruptHttp();
    }
}
